package com.c6906.vdam.das.model.dto;

public class ResultUtil {
    public static ResultInfo getSuccessResult(Object data) {
        ResultInfo resultInfo = new ResultInfo();
        resultInfo.setCode(ResultCode.SUCCESS.getCode());
        resultInfo.setMessage(ResultCode.SUCCESS.getMsg());
        resultInfo.setData(data);
        return resultInfo;
    }

    public static ResultInfo getSuccessResult(String resultMessage, Object data) {
        ResultInfo resultInfo = new ResultInfo();
        resultInfo.setCode(ResultCode.SUCCESS.getCode());
        resultInfo.setMessage(resultMessage);
        resultInfo.setData(data);
        return resultInfo;
    }

    public static ResultInfo getFailResult(Object data) {
        ResultInfo resultInfo = new ResultInfo();
        resultInfo.setCode(ResultCode.BIZ_EXCEPTION.getCode());
        resultInfo.setMessage(ResultCode.BIZ_EXCEPTION.getMsg());
        resultInfo.setData(data);
        return resultInfo;
    }

    public static ResultInfo getFailResult(ResultCode resultCode) {
        return getFailResult(resultCode, null);
    }

    public static ResultInfo getFailResult(String resultCode, String resultMessage, Object data) {
        ResultInfo resultInfo = new ResultInfo();
        resultInfo.setCode(resultCode);
        resultInfo.setMessage(resultMessage);
        resultInfo.setData(data);
        return resultInfo;
    }

    public static ResultInfo getFailResult(ResultCode resultCode, Object data) {
        ResultInfo resultInfo = new ResultInfo();
        resultInfo.setCode(resultCode.getCode());
        resultInfo.setMessage(resultCode.getMsg());
        resultInfo.setData(data);
        return resultInfo;
    }

    public static <T> ResultInfo<T> buildSuccessResult(T t) {
        ResultInfo resultInfo = new ResultInfo();
        resultInfo.setData(t);
        resultInfo.setMessage(ResultCode.SUCCESS.getMsg());
        resultInfo.setCode(ResultCode.SUCCESS.getCode());
        return resultInfo;
    }

    public static <T> ResultInfo<T> buildFailResult(T t) {
        ResultInfo resultInfo = new ResultInfo();
        resultInfo.setData(t);
        resultInfo.setCode(ResultCode.FAILED.getCode());
        resultInfo.setMessage(ResultCode.FAILED.getMsg());
        return resultInfo;
    }

    public static <T> ResultInfo<T> buildFailResult(String resultCode, String resultMessage, T t) {
        ResultInfo resultInfo = new ResultInfo();
        resultInfo.setData(t);
        resultInfo.setCode(resultCode);
        resultInfo.setMessage(resultMessage);
        return resultInfo;
    }
}
